C_a_vec = C_a_bar_vec + (wage_guesses - P_a_vec.*C_a_bar - P_m_vec.*C_m_bar - P_s_vec.*C_s_bar) ...
    ./ (P_m_vec.^(1-sigma).*P_a_vec.^sigma.*(omega_m/omega_a)+P_s_vec.^(1-sigma).*P_a_vec.^sigma.*(omega_s/omega_a)+P_a_vec);
C_m_vec = C_m_bar_vec + (wage_guesses - P_a_vec.*C_a_bar - P_m_vec.*C_m_bar - P_s_vec.*C_s_bar) ...
    ./ (P_a_vec.^(1-sigma).*P_m_vec.^sigma.*(omega_a/omega_m)+P_s_vec.^(1-sigma).*P_m_vec.^sigma.*(omega_s/omega_m)+P_m_vec);
C_s_vec = C_s_bar_vec + (wage_guesses - P_a_vec.*C_a_bar - P_m_vec.*C_m_bar - P_s_vec.*C_s_bar) ...
    ./ (P_a_vec.^(1-sigma).*P_s_vec.^sigma.*(omega_a/omega_s)+P_m_vec.^(1-sigma).*P_s_vec.^sigma.*(omega_m/omega_s)+P_s_vec);

P_bar_vec = (omega_a.*P_a_vec.^(1-sigma)+omega_m.*P_m_vec.^(1-sigma)+omega_s.*P_s_vec.^(1-sigma)).^(1/(1-sigma));

exp_share_ag_vec = (C_a_vec.*P_a_vec)./wage_guesses;
exp_share_manu_vec = (C_m_vec.*P_m_vec)./wage_guesses;
exp_share_serv_vec = (C_s_vec.*P_s_vec)./wage_guesses;

C_a_vec_temp = C_a_vec;
C_a_vec_temp(C_a_vec<C_a_bar_vec) = C_a_bar_vec(C_a_vec<C_a_bar_vec);

C_vec = (omega_a^(1/sigma).*(C_a_vec_temp-C_a_bar_vec).^((sigma-1)/sigma)+omega_m^(1/sigma).*(C_m_vec-C_m_bar_vec).^((sigma-1)/sigma)...
    +omega_s^(1/sigma).*(C_s_vec-C_s_bar_vec).^((sigma-1)/sigma)).^(sigma/(sigma-1));